<template>
	<view>
		<u-cell-group>
			<u-cell v-for="item in orderlist" :key="item.id">
				<view slot="title">
					<view style="padding-bottom: 5px;">用户名： {{item.business.nickname}}</view>
					<view style="padding-bottom: 5px;">课程名称： {{item.subject.title}}</view>
					<view style="padding-bottom: 5px;">价格： ￥{{item.total}}</view>
				</view>
				<view slot="value">
					<u-button type="error" text="删除" :customStyle="btnStyle" size="min" @click="del(item)"></u-button>
				</view>
				<view slot="label">
					<view style="color: #909193;">订单号： {{item.code}}</view>
				</view>
			</u-cell>
		</u-cell-group>
		<!-- 消息提示 -->
		<u-toast ref="uToast"></u-toast>
		<!-- 确认框 -->
		<u-modal :show="show" :content='content' :showCancelButton="true" @cancel="show = false"
			@confirm="confirm"></u-modal>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				btnStyle: {
					width: '100%',
					display: "inline-block",
					height: '25px',
					fontSize: '10px',
					padding: '5px 15px'
				},
				LoginUser: {},
				orderlist: [],
				show: false,
				content: '确认是否删除当前课程订单？',
				orderid: 0
			}
		},
		onShow() {
			this.$u.auth.check()
			this.LoginUser = uni.getStorageSync('LoginUser') ? uni.getStorageSync('LoginUser') : {};
			this.getOrderData()
		},
		methods: {
			async getOrderData() {
				let result = await this.$u.api.business.OrderIndex()
				if (result.code == 1) {
					this.orderlist = result.data
				}
			},
			del(item) {
				this.show = true;
				this.orderid = item.id
			},
			async confirm() {
				this.show = false;
				let result = await this.$u.api.business.OrderDel({
					adminid: this.LoginUser.id ?? 1,
					orderid: this.orderid
				})
				if (result.code == 1) {
					this.$refs.uToast.show({
						type: 'success',
						message: result.msg,
					})
					this.getOrderData()
				} else {
					this.$refs.uToast.show({
						type: 'error',
						message: result.msg,
					})
				}
			}
		}
	}
</script>

<style>
</style>